// pages/agency/index.js

const other = require('../../service/other')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    goodsactive: true,
    customeractive: false,
    listdata: [],
    param: {},
    params:{}
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let param = {
      data: { cutomerId:  wx.getStorageSync("userInfo").id, },
      "queryRequest": {
        "pageSize": "100",
        "pageNum": "1"
      }
    }
    let params = {
      data: { id:  wx.getStorageSync("userInfo").id, },
      "queryRequest": {
        "pageSize": "100",
        "pageNum": "1"
      }
    }
    this.setData({ param: param ,params:params})
    
  },
  getMyAgentList() {
    let param = this.data.param
    wx.showLoading({
      title: '加载中',
    })
    other.getMyAgentList(param, (res) => {
      wx.hideLoading();
      let listdata = res.data.rows || []
      listdata.forEach(item => {
        let imagesList = item.images.split(',') || []
        item.headerImage = imagesList[0] || ''
        item.percent = item.buyMoney / item.standard || item.buySum / item.standard
      })
      this.setData({
        listdata: res.data.rows
      })
    })
  },
  getMyCustomerList() {
    
    let params = this.data.params
    wx.showLoading({
      title: '加载中',
    })
    other.getMyCustomerList(params, (res) => {
      wx.hideLoading();
      this.setData({
        listdata: res.data.rows
      })
    })
  },

  onShow() {
    if (this.data.goodsactive) {
      this.getMyAgentList()
    }

    if (this.data.customeractive) {
      this.getMyCustomerList()
    }
  },

  mygoodsTo() {
    this.getMyAgentList()
    this.setData({
      goodsactive: true,
      customeractive: false
    })
  },
  mycustomerTo() {
    this.getMyCustomerList()
    this.setData({
      goodsactive: false,
      customeractive: true
    })
  },
  processTo() {
    wx.navigateTo({
      url: '/pages/agency/process/index',
    })
  },

  goApply() {
    wx.navigateTo({
      url: '/pages/agency/apply/index',
    })
  },
  godetail(e){
    //console.log(e)
    wx.navigateTo({
      url: '/pages/product/productDetail/index?id=' + e.currentTarget.dataset.item,
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})